package com.mypack.bookStore.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
/**
 * 该类implements  UserDetails接口,
 * 验证成功后 保存在当前会话的 principal对象中
 * @author JackDosen
 * SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 * jsp中
 * <sec:authentication property="principal.username"/>
 */
public class WebUserDetails implements UserDetails {
	private String username;
	private String password;
	private boolean userEnabled;
	private Collection<GrantedAuthority> authorities;
	private boolean accountNonExpired;
	private boolean accountNonLocked;
	private boolean credentialsNonExpired;
	
	private int userId;
	
	public WebUserDetails(int userId,String username,String password,boolean userEnabled,Collection<GrantedAuthority> authorities) {
		this.username=username;
		this.password=password;
		this.userEnabled=userEnabled;
		this.authorities=authorities;
		
		//这里先都为true，如果要深度控制，完善
		this.accountNonExpired=true;
		this.accountNonLocked=true;
		this.credentialsNonExpired=true;
		this.userId=userId;
	}
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	@Override
	public String getPassword() {
		return this.password;
	}

	@Override
	public String getUsername() {
		return this.username;
	}

	@Override
	public boolean isAccountNonExpired() {
		return this.accountNonExpired;
	}

	@Override
	public boolean isAccountNonLocked() {
		return this.accountNonLocked;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return this.credentialsNonExpired;
	}

	@Override
	public boolean isEnabled() {
		return this.isEnabled();
	}

}
